package com.czl.module_storehouse.mvp.model;

import android.util.Log;

import com.czl.base.BuildConfig;
import com.czl.base.data.bean.tengyun.ReceiveBean;
import com.czl.base.data.net.RetrofitClient;
import com.czl.module_base.bean.ListBean;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_storehouse.api.ApiService;
import com.czl.module_storehouse.bean.ReceiveInfoBean;
import com.google.gson.Gson;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @author by xubin,
 * @date on 2022/2/22.
 * PS: Not easy to write code, please indicate.
 */
public class ReceiveModel extends BasicDataModel {
    public Observable<HttpResponse<Object>> addReceiveInfo(ReceiveInfoBean bean) {
        bean.setReceiveCompanyId(getManageCompanyId());
        bean.setReceiveCompanyName(getManageCompanyName());
        bean.setReceiveCompanyShortName(getStoreCompanyShortName());
        bean.setStorehouseId(getStorehouseId());
        bean.setOperaterId(getUserId());
        bean.setOperaterName(getTName());
        Gson gson = new Gson();
        String json = gson.toJson(bean);
        if (BuildConfig.DEBUG) {
            Log.e(TAG, "ReceiveReturnNeedBean :" + json);
        }
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RetrofitClient.getInstance().create(ApiService.class)
                .addReceiveInfo(RequestBody.create(mediaType, json));
    }

    public Observable<HttpResponse<Object>> editReceiveInfo(ReceiveInfoBean bean) {
        bean.setReceiveCompanyId(getManageCompanyId());
        bean.setReceiveCompanyName(getManageCompanyName());
        bean.setReceiveCompanyShortName(getStoreCompanyShortName());
        bean.setStorehouseId(getStorehouseId());
        bean.setOperaterId(getUserId());
        bean.setOperaterName(getTName());
        Gson gson = new Gson();
        String json = gson.toJson(bean);
        if (BuildConfig.DEBUG) {
            Log.e(TAG, "ReceiveReturnNeedBean :" + json);
        }
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RetrofitClient.getInstance().create(ApiService.class)
                .editReceiveInfo(RequestBody.create(mediaType, json));
    }

    public Observable<HttpResponse<ListBean<ReceiveBean>>> getNeedDealtReceiveList(ReceiveInfoBean bean) {
        bean.setOperaterId(getUserId());
        bean.setOperaterName(getTName());
        Gson gson = new Gson();
        String json = gson.toJson(bean);
        if (BuildConfig.DEBUG) {
            Log.e(TAG, "ReceiveReturnNeedBean :" + json);
        }
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RetrofitClient.getInstance().create(ApiService.class)
                .getNeedDealtReceiveList(RequestBody.create(mediaType, json));
    }


}
